package com.sample.FinalProject;

import java.util.ArrayList;

import android.graphics.Color;
import android.graphics.Rect;

public class Building {
int x, y, length, color, health, max_health, type, maintain;
boolean isEnemy;
public Building(int xCoord, int yCoord, int colour, int aType){	
x=xCoord;
y=yCoord;
color=colour;
type=aType;
maintain=0;
if(colour==Color.GRAY){
isEnemy=true;	
}
else{
isEnemy=false;	
}
if (type==1){
length=60;	
max_health=5000;
health=max_health;
}
else if(type==2){
length=35;	
max_health=300;
health=max_health;
}
}
public Building(){
	
}
public boolean isEnemy(){
return isEnemy;	
}
public int getX(){
return x;	
}
public int getY(){
return y;	
}
public void setX(int newX){
x=newX;;	
}
public void setY(int newY){
y=newY;;	
}
public void setHealth(int newHealth){
health=newHealth;	
}
public int getLength(){
return length;	
}
public int getColor(){
return color;	
}	
public int getHealth(){
return health;	
}
public int getMaxHealth(){
return max_health;	
}
public int getType(){
return type;	
}
public void heal(FinalView fv){
MainShape main=fv.getMain();
ArrayList <Square> squares=fv.getSquares();
ArrayList <Circle> CircleUnits=fv.getCircleUnits();	
for (int w = 0; w<squares.size(); w++){
	if(isEnemy== squares.get(w).isEnemy() && squares.get(w).getX()>x && squares.get(w).getX()<x+length || isEnemy== squares.get(w).isEnemy() && squares.get(w).getX()+squares.get(w).getLength() > x && squares.get(w).getX()+squares.get(w).getLength() < x+length){
		if(squares.get(w).getY()>y && squares.get(w).getY()<y+length || squares.get(w).getY()+squares.get(w).getLength() > y && squares.get(w).getY()+squares.get(w).getLength() < y+length){
			if(squares.get(w).getHealth()<squares.get(w).getMaxHealth()){		
				squares.get(w).setHealth(squares.get(w).getHealth()+20);
				}
		}}
		}
for (int z = 0; z<CircleUnits.size(); z++){
	if(isEnemy== CircleUnits.get(z).isEnemy() && CircleUnits.get(z).getX()-CircleUnits.get(z).getRadius()>x && CircleUnits.get(z).getX()-CircleUnits.get(z).getRadius()<x+length || isEnemy== CircleUnits.get(z).isEnemy() && CircleUnits.get(z).getX()+CircleUnits.get(z).getRadius() > x && CircleUnits.get(z).getX()+CircleUnits.get(z).getRadius() < x+length){
		if(CircleUnits.get(z).getY()-CircleUnits.get(z).getRadius()>y && CircleUnits.get(z).getY()-CircleUnits.get(z).getRadius()<y+length || CircleUnits.get(z).getY()+CircleUnits.get(z).getRadius() > y && CircleUnits.get(z).getY()+CircleUnits.get(z).getRadius() < y+length){
			if(CircleUnits.get(z).getHealth()<CircleUnits.get(z).getMaxHealth()){		
				CircleUnits.get(z).setHealth(CircleUnits.get(z).getHealth()+20);
				}
		}}	
}
if(isEnemy==false && main.getX()>x && main.getX()<x+length || isEnemy==false && main.getX()+main.getLength() > x && main.getX()+main.getLength() < x+length){
	if(main.getY()>y && main.getY()<y+length || main.getY()+main.getLength() > y && main.getY()+main.getLength() < y+length){
if(main.getHealth()<main.getMaxHealth()){		
main.setHealth(main.getHealth()+20);
}
	}
}
}
public void maintain(){
if(health<max_health && maintain>=5){	
health++;	
maintain=0;
}	
else{
maintain++;	
}
}
}
